package cn.interestingshop.servlet.client;

import cn.interestingshop.entity.BaseOrder;
import cn.interestingshop.entity.Cart;
import cn.interestingshop.entity.User;
import cn.interestingshop.entity.UserAddress;
import cn.interestingshop.service.BaseOrderService;
import cn.interestingshop.service.UserAddressService;
import cn.interestingshop.service.impl.BaseOrderServiceImpl;
import cn.interestingshop.service.impl.UserAddressServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/UserAddressSelectAllServlet")
public class UserAddressSelectAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.设置编码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        //2.获取请求参数
        User user=(User)request.getSession().getAttribute("loginUser");
        //3.调用service进行业务处理
        UserAddressService service=new UserAddressServiceImpl();
        List<UserAddress> addressList = service.selectAll(user.getId());
        //4.分析返回结果
        request.setAttribute("addressList",addressList);
        request.getRequestDispatcher("BuyCar_Two.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
